﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

using HongShijin.Collections;

namespace FarmilyEditor
{
	static class Common
	{
		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main()
		{
			//CNameObjectCollection noc0 = new CNameObjectCollection();
			//CNameObjectCollection noc1 = new CNameObjectCollection();
			//noc0.Add("a", "a");
			//noc1.Add("a", "a");
			//noc0.Add("0", "0");
			//noc0.Add("1", "1");
			//noc1.Add("1", "1");
			//noc1.Add("0", "0");
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			Application.Run(new FormMain());
		}
	}

	public class ListItem
	{
		protected int _DisplayIndex = -1;
		protected string _DisplayKey = null;
		protected CNameObjectCollection _Values = null;

		public ListItem(int displayIndex, CNameObjectCollection values)
		{
			this.DisplayIndex = displayIndex;
			this.Values = values;
		}

		public ListItem(string displayKey, CNameObjectCollection values)
		{
			this.DisplayKey = displayKey;
			this.Values = values;
		}

		public object this[int index]
		{
			set
			{
				this.Values[index] = value;
			}
			get
			{
				return this.Values[index];
			}
		}

		public object this[string key]
		{
			set
			{
				this.Values[key] = value;
			}
			get
			{
				return this.Values[key];
			}
		}

		public int DisplayIndex
		{
			set
			{
				this._DisplayIndex = value;
			}
			get
			{
				return this._DisplayIndex;
			}
		}

		public string DisplayKey
		{
			set
			{
				this._DisplayKey = value;
			}
			get
			{
				return this._DisplayKey;
			}
		}

		public CNameObjectCollection Values
		{
			set
			{
				this._Values = value;
			}
			get
			{
				return this._Values;
			}
		}

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		public override bool Equals(object obj)
		{
			if (obj == null || !(obj is ListItem))
				return false;

			ListItem lt = (ListItem)obj;
			if (this.DisplayIndex != lt.DisplayIndex)
				return false;

			if (this.DisplayKey != lt.DisplayKey)
				return false;

			return CNameObjectCollection.EqualsByKey(this.Values, lt.Values);
		}

		public override string ToString()
		{
			if (this.Values == null)
				return base.ToString();

			if (this.DisplayIndex >= 0 && this.DisplayIndex < this.Values.Count)
				return this.Values[this.DisplayIndex].ToString();

			if(string.IsNullOrEmpty(this.DisplayKey))
				return base.ToString();

			return this.Values[this.DisplayKey] + string.Empty;
		}

		public static CNameObjectCollection CreateValueCollection()
		{
			return new CNameObjectCollection();
		}
	}
}
